package com.edu.exam.enums;

/**
 * 可用性状态枚举
 * 
 * @author S-01 Module Designer
 * @version 2.0
 * @since 2025-11-10
 */
public enum AvailabilityStatus {
    AVAILABLE("available", "可用"),
    UNAVAILABLE("unavailable", "不可用"),
    BUSY("busy", "忙碌"),
    RESERVED("reserved", "已预约"),
    ON_LEAVE("on_leave", "请假"),
    SICK("sick", "病假"),
    TRAINING("training", "培训中"),
    MEETING("meeting", "会议中"),
    TRAVEL("travel", "出差中"),
    TEMPORARY_UNAVAILABLE("temporary_unavailable", "临时不可用"),
    PREFERRED("preferred", "首选"),
    ALTERNATE("alternate", "备选"),
    STANDBY("standby", "待命"),
    OUT_OF_OFFICE("out_of_office", "外出"),
    LIMITED("limited", "受限"),
    FULL("full", "满负荷"),
    PARTIAL("partial", "部分可用"),
    SCHEDULED("scheduled", "已安排"),
    FLEXIBLE("flexible", "灵活"),
    FIXED("fixed", "固定"),
    SEASONAL("seasonal", "季节性"),
    WEEKEND_ONLY("weekend_only", "仅周末"),
    WEEKDAY_ONLY("weekday_only", "仅工作日");

    private final String code;
    private final String description;

    AvailabilityStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取枚举值
     *
     * @param code 代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码无效
     */
    public static AvailabilityStatus fromCode(String code) {
        for (AvailabilityStatus status : AvailabilityStatus.values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown availability status code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 枚举描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述不存在
     */
    public static AvailabilityStatus fromDescription(String description) {
        for (AvailabilityStatus status : AvailabilityStatus.values()) {
            if (status.description.equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown availability status description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}